const updateApp = showMsg => {
	// 获取应用版本号
	const getVersion = () => {
		return new Promise(resolve => {
			plus.runtime.getProperty(plus.runtime.appid, wgtinfo => {
				resolve(wgtinfo.version);
			});
		});
	};

	return new Promise(resolve => {
		uni.request({
			url: `${global.$updateHost}app/common/getVersion/6`,
			method: 'GET',
			success: res => {
				if (res.statusCode !== 200 || res.data.statusCode !== '200') {
					showMsg && uni.showToast({
						title: '版本获取失败',
						icon: 'none'
					});
					return;
				}
				getVersion().then(version => {
					if (res.data.version.versionNumber <= version) {
						showMsg && uni.showToast({
							title: '您已安装最新版本',
							icon: 'none'
						});
						return;
					}
					resolve(res.data.version.uploadPath);
				});
			},
			fail: res => {
				showMsg && uni.showToast({
					title: '版本获取失败',
					icon: 'none'
				});
			}
		});
	});
}

export default {
	updateApp
}
